/******************************************************************************/
/********************************** 平台相关 **********************************/
/******************************************************************************/

import { TostMessageType } from "@/types";
import { ElMessage } from "element-plus";
import type { MessageParams } from "element-plus";

/**
 * 展示message提示信息，默认展示成功通知
 * @param hint string, MessageParams 提示内容
 */
export function showMessage(
  hint: string | MessageParams,
  type: TostMessageType = "success"
) {
  if (!hint) return;
  if (typeof hint !== "string") return ElMessage(hint);
  const speed = 7; //速度：7字/秒
  let duration = (hint.length / speed) * 1000;
  if (duration < 1500) duration = 1500;
  ElMessage({
    message: hint,
    type,
    duration,
    grouping: true,
    showClose: duration > 2000,
  } as MessageParams);
}
